﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PFI.SCHVN;
using System.Collections;
using Algorithm.UsefulMethods;
using Algorithm.UsefulMethods.Extensions;
using System.Diagnostics;


namespace Utils.RamDevice
{
    public static partial class RAM
    {
        public static class CletchingCombinations
        {
            public static List<KeyValuePair<int[], int[]>> masOfCletchingCombinations { get; private set; }

            static CletchingCombinations()
            {
                masOfCletchingCombinations = new List<KeyValuePair<int[], int[]>>();
            }

            public static void ClearCletchingCombinations()
            {
                masOfCletchingCombinations.Clear();
            }
            /// <summary>
            /// AddCletchingCombination assuming that combinations is added from lowest to highest
            /// </summary>
            /// <param name="valueHigh">key</param>
            /// <param name="valueLow">value</param>
            public static void AddCletchingCombination(int[] valueHigh, int[] valueLow)
            {
                masOfCletchingCombinations.Add(new KeyValuePair<int[], int[]>(valueHigh, valueLow));
            }

            public static int[] CheckAndGetCletchingCombinationUp(int[] toFind)
            {
                foreach (var cletchingCombination in masOfCletchingCombinations)
                {
                    if (cletchingCombination.Value.CompareInts(toFind))
                    {
                        Trace.WriteLine(string.Format("High {0} Low {1}", ArrayToString.Convert(cletchingCombination.Value), ArrayToString.Convert(toFind)));
                        return cletchingCombination.Key;
                    }
                }
                return null;

            }
            public static int[] CheckAndGetCletchingCombinationsDown(int[] toFind)
            {
                foreach (var cletchingCombination in masOfCletchingCombinations)
                {
                    if (cletchingCombination.Key.CompareInts(toFind))
                    {
                        return cletchingCombination.Value;
                    }
                }
                return null;
            }

        }
    }
}
